/*
 * jxSwing Project (2014)
 * 
 * by Denilson Edinaldo Pinto
 * 
 * LGPL
 * Copyright (C) 2014
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.jxSwing.component.list;

import java.awt.Color;
import java.util.Vector;

import javax.swing.JList;
import javax.swing.ListModel;
import javax.swing.UIManager;
import javax.swing.border.LineBorder;

import org.jxSwing.component.JXComponent;
import org.jxSwing.i18n.I18N;
import org.jxUtils.check.CheckUtil;

/**
 * @author Denilson Edinaldo Pinto
 * @porject jxSwing
 * @package org.jxSwing.component.list
 * @date 15/11/2014 - 19:13:08
 */
public class List<T> extends JList<T> implements JXComponent {
	
	private static final long serialVersionUID = -1320768231109917674L;
	
	private boolean atributte = true;
	
	private boolean required = false;
	
	private boolean requiredBorderEnabled = true;
	
	private int index = -1;
	
	/**
	 * 
	 */
	public List() {
	
		super();
	}
	
	/**
	 * @param dataModel
	 */
	public List(ListModel<T> dataModel) {
	
		super(dataModel);
	}
	
	/**
	 * @param listData
	 */
	public List(T[] listData) {
	
		super(listData);
	}
	
	/**
	 * @param listData
	 */
	public List(Vector<? extends T> listData) {
	
		super(listData);
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jxSwing.component.JXComponent#getIndex()
	 */
	@Override
	public int getIndex() {
	
		return index;
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jxSwing.component.JXComponent#isAtributte()
	 */
	@Override
	public boolean isAtributte() {
	
		return atributte;
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jxSwing.component.JXComponent#isRequired()
	 */
	@Override
	public boolean isRequired() {
	
		return required;
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jxSwing.component.JXComponent#isRequiredBorderEnabled()
	 */
	@Override
	public boolean isRequiredBorderEnabled() {
	
		return requiredBorderEnabled;
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jxSwing.component.JXComponent#setAtributte(boolean)
	 */
	@Override
	public void setAtributte(boolean atributte) {
	
		this.atributte = atributte;
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jxSwing.component.JXComponent#setIndex(int)
	 */
	@Override
	public void setIndex(int index) {
	
		this.index = index;
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see java.awt.Component#setName(java.lang.String)
	 */
	@Override
	public void setName(final String name) {
	
		super.setName(name);
		
		setRequired(isRequired());
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jxSwing.component.JXComponent#setRequired(boolean)
	 */
	@Override
	public void setRequired(boolean required) {
	
		this.required = required;
		
		//
		if(required) {
			
			//
			if(isRequiredBorderEnabled()) {
				
				setBorder(new LineBorder(Color.RED));
			}
			
			//
			if(CheckUtil.isNullOrAbsoluteEmpty(getName())) {
				
				setToolTipText(I18N.component().requiredThis());
				
			}else {
				
				setToolTipText(I18N.component().requiredField(getName()));
			}
			
		}else {
			
			setBorder(UIManager.getBorder("List.border"));
			setToolTipText(null);
		}
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jxSwing.component.JXComponent#setRequiredBorderEnabled(boolean)
	 */
	@Override
	public void setRequiredBorderEnabled(boolean requiredBorderEnabled) {
	
		this.requiredBorderEnabled = requiredBorderEnabled;
	}
}
